package com.ruoyi.store.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.store.domain.StockTaking;
import com.ruoyi.store.service.IStockTakingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 库存盘点Controller
 * 
 * @author lmj
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/StockTaking")
@Slf4j
public class StockTakingController extends BaseController
{
    @Autowired
    private IStockTakingService stockTakingService;

    /**
     * 查询库存盘点列表
     */
    @RequiresPermissions("store:StockTaking:list")
    @GetMapping("/list")
    public TableDataInfo list(StockTaking stockTaking)
    {
        startPage();
        List<StockTaking> list = stockTakingService.selectStockTakingList(stockTaking);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点列表
     */
    @RequiresPermissions("store:StockTaking:export")
    @Log(title = "库存盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockTaking stockTaking)
    {
        List<StockTaking> list = stockTakingService.selectStockTakingList(stockTaking);
        ExcelUtil<StockTaking> util = new ExcelUtil<StockTaking>(StockTaking.class);
        util.exportExcel(response, list, "库存盘点数据");
    }

    /**
     * 获取库存盘点详细信息
     */
    @RequiresPermissions("store:StockTaking:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(stockTakingService.selectStockTakingById(id));
    }

    /**
     * 新增库存盘点
     */
    @RequiresPermissions("store:StockTaking:add")
    @Log(title = "库存盘点", businessType = BusinessType.INSERT)
    @PostMapping("addStockTaking")
    public AjaxResult addStockTaking(@RequestBody StockTaking stockTaking)
    {
        log.info("StockTakingController addStockTaking params:{}",stockTaking);
        return stockTakingService.insertStockTaking(stockTaking);
    }

    /**
     * 修改库存盘点
     */
    @RequiresPermissions("store:StockTaking:edit")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PostMapping("updStockTaking")
    public AjaxResult edit(@RequestBody StockTaking stockTaking)
    {
        log.info("StockTakingController editStockTaking params:{}",stockTaking);
        return stockTakingService.updateStockTaking(stockTaking);
    }

    /**
     * 删除库存盘点
     */
    @RequiresPermissions("store:StockTaking:remove")
    @Log(title = "库存盘点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(stockTakingService.deleteStockTakingByIds(ids));
    }
}
